package com.erp.order.purchasing.controller;

import com.erp.hr.base.controller.BaseController;
import com.erp.hr.base.vo.ResultVO;
import com.erp.order.purchasing.model.InquiryList;
import com.erp.order.purchasing.model.PriceParityVO;
import com.erp.order.purchasing.service.InquiryListService;
import org.redragon.framework.hibernate.model.Pages;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 询价单 控制层
 * @Author: syz
 * @blame syz
 * @CreateTime: 2021/4/6
 */
@Controller
@RequestMapping("web/inquiryList")
public class InquiryListController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(InquiryListController.class);

    /**
     * 询价单服务
     */
    @Autowired
    private InquiryListService inquiryListService;


    /**
     * 获取列表分页数据
     * @param pages 分页对象
     * @param inquiryList 询价单对象
     * @param model 模型对象
     * @return 页面路径
     */
    @RequestMapping("getPageList")
    public String getPageList(Pages pages, InquiryList inquiryList, Model model) {
        model.addAttribute("pages", setPages(pages));
        model.addAttribute("list", inquiryListService.addCompleteData(inquiryListService.getDataObjectsForDataAuth("", pages, inquiryList)));
        model.addAttribute("procurementTypeMap", inquiryListService.getDictByKey("procurement_type"));
        model.addAttribute("statusMap", inquiryListService.getDictByKey("inquiry_status"));
        return "basic.jsp?content=inquiryList/list";
    }

    /**
     * 跳转至新增页面
     * @param model 模型对象
     * @return 页面路径
     */
    @RequestMapping("get")
    public String get(Model model) {
        model.addAttribute("procurementTypeMap", inquiryListService.getDictByKey("procurement_type"));
        model.addAttribute("inquiryTypeMap", inquiryListService.getDictByKey("inquiry_type"));
        model.addAttribute("quoteRequestMap", inquiryListService.getDictByKey("quote_request"));
        model.addAttribute("tradingMannerMap", inquiryListService.getDictByKey("trading_manner"));
        model.addAttribute("designatedSettlementDateMap", inquiryListService.getDictByKey("designated_settlement_date"));
        model.addAttribute("settlementDateMap", inquiryListService.getDictByKey("settlement_date"));
        model.addAttribute("paymentStageMap", inquiryListService.getDictByKey("payment_stage"));
        model.addAttribute("paymentMap", inquiryListService.getDictByKey("payment"));
        model.addAttribute("invoiceRequirementsMap", inquiryListService.getDictByKey("invoice_requirements"));
        model.addAttribute("certificationRequirementsMap", inquiryListService.getDictByKey("certification_requirements"));
        model.addAttribute("bookBuildingMap", inquiryListService.getDictByKey("book_building"));
        model.addAttribute("procurementPortalMap", inquiryListService.getDictByKey("procurement_portal"));
        model.addAttribute("priceComparisonWayMap", inquiryListService.getDictByKey("price_comparison_way"));
        model.addAttribute("contactWayMap", inquiryListService.getDictByKey("contact_way"));
        model.addAttribute("unitMap", inquiryListService.getDictByKey("material_unit"));
        return "basic.jsp?content=inquiryList/edit";
    }

    /**
     * 新增
     * @param inquiryList 需要新增的对象
     * @return 新增结果
     */
    @ResponseBody
    @RequestMapping("save")
    public ResultVO<String> save(@RequestBody InquiryList inquiryList) {
        return save(inquiryListService, inquiryList);
    }

    /**
     * 跳转至比价页
     * @param inquiryList 询价单对象
     * @param model 模型对象
     * @return 页面路径
     */
    @RequestMapping("toPriceParity")
    public String toPriceParity(InquiryList inquiryList, Model model) {
        model.addAttribute("inquiryList", inquiryListService.addCompleteData(inquiryListService.getDataObject(inquiryList.getId().toString())));
        model.addAttribute("unitMap", inquiryListService.getDictByKey("material_unit"));
        return "basic.jsp?content=inquiryList/priceParity";
    }

    /**
     * 比价
     * @param priceParityVO 比价vo对象
     * @return 比价结果
     */
    @ResponseBody
    @RequestMapping("priceParity")
    public ResultVO<String> priceParity(@RequestBody PriceParityVO priceParityVO) {
        return inquiryListService.priceParity(priceParityVO);
    }

    /**
     * 跳转至详情页
     * @param inquiryList 询价单对象
     * @param model 模型对象
     * @return 页面路径
     */
    @RequestMapping("detail")
    public String detail(InquiryList inquiryList, Model model) {
        model.addAttribute("inquiryList",
                inquiryListService.addCompleteData(
                        inquiryListService.getDataObject(
                                inquiryList.getId().toString())));
        model.addAttribute("procurementTypeMap", inquiryListService.getDictByKey("procurement_type"));
        model.addAttribute("inquiryTypeMap", inquiryListService.getDictByKey("inquiry_type"));
        model.addAttribute("quoteRequestMap", inquiryListService.getDictByKey("quote_request"));
        model.addAttribute("tradingMannerMap", inquiryListService.getDictByKey("trading_manner"));
        model.addAttribute("designatedSettlementDateMap", inquiryListService.getDictByKey("designated_settlement_date"));
        model.addAttribute("settlementDateMap", inquiryListService.getDictByKey("settlement_date"));
        model.addAttribute("paymentStageMap", inquiryListService.getDictByKey("payment_stage"));
        model.addAttribute("paymentMap", inquiryListService.getDictByKey("payment"));
        model.addAttribute("invoiceRequirementsMap", inquiryListService.getDictByKey("invoice_requirements"));
        model.addAttribute("certificationRequirementsMap", inquiryListService.getDictByKey("certification_requirements"));
        model.addAttribute("bookBuildingMap", inquiryListService.getDictByKey("book_building"));
        model.addAttribute("procurementPortalMap", inquiryListService.getDictByKey("procurement_portal"));
        model.addAttribute("priceComparisonWayMap", inquiryListService.getDictByKey("price_comparison_way"));
        model.addAttribute("contactWayMap", inquiryListService.getDictByKey("contact_way"));
        model.addAttribute("procurementMethodMap", inquiryListService.getDictByKey("procurement_method"));
        model.addAttribute("unitMap", inquiryListService.getDictByKey("material_unit"));
        return "basic.jsp?content=inquiryList/detail";
    }

    /**
     * 跳转至比价结果页
     * @param inquiryList 询价单对象
     * @param model 模型对象
     * @return 页面路径
     */
    @RequestMapping("priceParityResult")
    public String priceParityResult(InquiryList inquiryList, Model model) {
        inquiryList = inquiryListService.addCompleteData(
                inquiryListService.getDataObject(
                        inquiryList.getId().toString()));
        model.addAttribute("inquiryList", inquiryList);
        model.addAttribute("procurementTypeMap", inquiryListService.getDictByKey("procurement_type"));
        model.addAttribute("taskInfoList", inquiryListService.getTaskInfo(inquiryList.getProcessInstanceId()));
        model.addAttribute("inquiryTypeMap", inquiryListService.getDictByKey("inquiry_type"));
        model.addAttribute("quoteRequestMap", inquiryListService.getDictByKey("quote_request"));
        model.addAttribute("tradingMannerMap", inquiryListService.getDictByKey("trading_manner"));
        model.addAttribute("designatedSettlementDateMap", inquiryListService.getDictByKey("designated_settlement_date"));
        model.addAttribute("settlementDateMap", inquiryListService.getDictByKey("settlement_date"));
        model.addAttribute("paymentStageMap", inquiryListService.getDictByKey("payment_stage"));
        model.addAttribute("paymentMap", inquiryListService.getDictByKey("payment"));
        model.addAttribute("invoiceRequirementsMap", inquiryListService.getDictByKey("invoice_requirements"));
        model.addAttribute("certificationRequirementsMap", inquiryListService.getDictByKey("certification_requirements"));
        model.addAttribute("bookBuildingMap", inquiryListService.getDictByKey("book_building"));
        model.addAttribute("procurementPortalMap", inquiryListService.getDictByKey("procurement_portal"));
        model.addAttribute("priceComparisonWayMap", inquiryListService.getDictByKey("price_comparison_way"));
        model.addAttribute("contactWayMap", inquiryListService.getDictByKey("contact_way"));
        model.addAttribute("procurementMethodMap", inquiryListService.getDictByKey("procurement_method"));
        model.addAttribute("unitMap", inquiryListService.getDictByKey("material_unit"));
        return "basic.jsp?content=inquiryList/priceParityResult";
    }

}